import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { IBusinessUser } from './useBusinessUsers'
import { IChannelOrigin } from './useChannels'
import { ICountry } from './useCountries'
import { IEnterpriseConnector } from './useEnterpriseConnectors'
import { IServiceProvider } from './useMerchants'

axiosMock('default', mock => {
  // 获取服务商列表
  mock.onGet(RegExp(`/api/admin/merchants`)).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: {
          records: Array(randArrItem([10, 30, 100]))
            .fill(null)
            .map<IServiceProvider>((_item, index) => {
              return {
                id: index,
                name: `服务商名称${index + 1}`,
              }
            }),
        },
      }
    }),
  )

  // 获取物流渠道列表
  mock.onGet(`/api/admin/channels/all`).reply(
    delayFn<IChannelOrigin[]>(600, () => {
      return {
        success: true,
        data: Array(randArrItem([10, 30, 60, 90]))
          .fill(null)
          .map<IChannelOrigin>((_d, i) => ({
            id: i,
            name: randArrItem([`渠道名称${i}`]),
            code: randArrItem([`渠道代码${i}`], 0.1),
            inlineName: randArrItem([`内置名${i}`], 0.1),
            merchant: randArrItem([`服务商${i}`], 0.1),
            countryName: randArrItem([`目的国${i}`], 0.1),
            firstLine: randArrItem([1, 2, 3, 4], 0.1),
            tailLine: randArrItem([1, 2], 0.1),
          })),
      }
    }),
  )

  // 获取国家列表
  mock.onGet(RegExp(`/api/admin/countries/all`)).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: Array(randArrItem([10, 30, 100]))
          .fill(null)
          .map<ICountry>((_item, index) => {
            return {
              id: index,
              code: randArrItem(['US']),
              chineseName: `国家${index + 1}`,
            }
          }),
      }
    }),
  )

  // 人员 获取业务跟单人员列表
  mock.onGet(RegExp(`/omsapi/dispatchOrder/businessUsers`)).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: Array(randArrItem([10, 30, 100]))
          .fill(null)
          .map<IBusinessUser>((_item, index) => {
            return {
              id: index,
              name: randArrItem([`用户名称${index + 1}`], 0.1),
              englishName: randArrItem([`用户英文名称${index + 1}`], 0.1),
            }
          }),
      }
    }),
  )

  // 客户 获取企业联系人列表
  mock.onGet(RegExp(`/api/admin/enterprise/connectors`)).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: Array(randArrItem([10, 30, 100]))
          .fill(null)
          .map<Omit<IEnterpriseConnector, '$showName'>>((_item, index) => {
            return {
              id: index,
              firstName: randArrItem([`firstName${index + 1}`], 0.1),
              lastName: randArrItem([`lastName${index + 1}`], 0.1),
              enterpriseName: randArrItem([`enterpriseName${index + 1}`], 0.1),
            }
          }),
      }
    }),
  )
})
